package xuesm.singleton;

import xuesm.singleton.register.ContainerSingleton;
import xuesm.singleton.register.EnumSingleton;
import xuesm.singleton.threadlocal.ThreadLocalSingleton;

/**
 * @Author: xuesm
 * @Description:	线程类
 * @Date: Create in 13:03 2019/3/27
 */
public class ExectorThread implements Runnable {
	@Override
	public void run() {

		// 饿汉式单例
//		HungrySingleton singleton = HungrySingleton.getInstance();
//		System.out.println(Thread.currentThread().getName() + " : " + singleton);

		// 简单懒汉式单例
//		LazySimpleSingleton singleton = LazySimpleSingleton.getInstance();
//		System.out.println(Thread.currentThread().getName() + " : " + singleton);

		// 双重锁单例
//		LazyDoubleCheckSingleton singleton = LazyDoubleCheckSingleton.getInstance();
//		System.out.println(Thread.currentThread().getName() + " : " + singleton);

		// 静态内部类单例
//		LazyInnerClassSingleton singleton = LazyInnerClassSingleton.getInstance();
//		System.out.println(Thread.currentThread().getName() + " : " + singleton);

		// 枚举登记式单例测试
//		EnumSingleton singleton = EnumSingleton.getInstance();
//		singleton.setData(new Object());
//		System.out.println(Thread.currentThread().getName() + " : " + singleton.getData());

		// 容器登记式单例测试
//		ContainerSingleton singleton = (ContainerSingleton) ContainerSingleton.getInstance(ContainerSingleton.class.getName());
//		System.out.println(Thread.currentThread().getName() + " : " + singleton);

		// ThreadLoad单例测试
		System.out.println(Thread.currentThread().getName() + " - " + ThreadLocalSingleton.getInstance());
		System.out.println(Thread.currentThread().getName() + " - " + ThreadLocalSingleton.getInstance());
		System.out.println(Thread.currentThread().getName() + " - " + ThreadLocalSingleton.getInstance());
		System.out.println(Thread.currentThread().getName() + " - " + ThreadLocalSingleton.getInstance());
		System.out.println(Thread.currentThread().getName() + " - " + ThreadLocalSingleton.getInstance());
	}
}
